<template>
  <nav class="navbar">
    <div class="container">
     
      <router-link to="/" class="logo">
        <span>LifeLog</span>
        <span class="icon">📝</span>
      </router-link>
      
      <!-- 汉堡菜单按钮 -->
      <button class="hamburger" @click="toggleMenu">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
      </button>

      <!-- 导航链接 -->
      <div class="nav-items" :class="{ 'active': isMenuOpen }">
        <router-link 
    v-for="item in navItems" 
    :key="item.path" 
    :to="{ name: item.name }" 
    @click="closeMenu"
  >
    {{ item.name }}
  </router-link>
      </div>
      
      <ThemeToggle />
    </div>
  </nav>
</template>

<script setup>
import { ref } from 'vue'
import ThemeToggle from './ThemeToggle.vue'
const navItems = [
  { name: 'home', path: '/' },
  { name: 'diary-list', path: '/diary' },
  { name: 'about', path: '/about' }
]
// const navItems = [
//   { path: '/', name: '首页' },
//   { path: '/diary', name: '日记' },
//   { path: '/view', name: '关于' },
//   { path: '/about', name: '我的' }
// ]

const isMenuOpen = ref(false)

const toggleMenu = () => {
  isMenuOpen.value = !isMenuOpen.value
}

const closeMenu = () => {
  isMenuOpen.value = false
}
</script>

<style scoped>
.navbar {
  background: var(--card-bg);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem;
  position: relative;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}

.nav-items {
  display: flex;
  gap: 2rem;
  align-items: center;
  transition: all 0.3s ease;
}

.nav-items a {
  color: var(--text-color);
  text-decoration: none;
  transition: color 0.3s;
}

.nav-items a:hover {
  color: var(--primary);
}

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.hamburger span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text-color);
  margin: 5px 0;
  transition: all 0.3s ease;
}

@media (max-width: 768px) {
  .hamburger {
    display: block;
  }

  .nav-items {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    flex-direction: column;
    gap: 0;
    max-height: 0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }

  .nav-items.active {
    max-height: 300px;
    padding: 1rem 0;
  }

  .nav-items a {
    padding: 1rem;
    width: 100%;
    text-align: center;
  }
}
</style>